from flask import Blueprint, jsonify, request
from models import AccessLog
from flask_jwt_extended import jwt_required, get_jwt_identity

api = Blueprint('log_api', __name__)

@api.route('/', methods=['GET'])
@jwt_required()
def get_logs():
    page = request.args.get('page', default=1, type=int)
    limit = request.args.get('limit', default=10, type=int)
    query = AccessLog.query.order_by(AccessLog.id)
    pagination = query.paginate(page=page, per_page=limit, error_out=False)
    for log in pagination.items:
        temp = log.to_dict()
        print(temp)
    return jsonify({
        "code": 0,
        "msg": "查询成功",
        "page": page,
        "limit": limit,
        "count": pagination.total,
        "data": [log.to_dict() for log in pagination.items]
    })
